package com.example.project.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.example.project.entity.DictType;

/**
 * 字典表 数据层
 * 
 * @author ruoyi
 */
@Mapper
public interface DictTypeMapper {
	
	/**
	 * 根据条件分页查询字典类型
	 * 
	 * @param dictType 字典类型信息
	 * @return 字典类型集合信息
	 */
	@Select({"<script>",
		"select dict_id, dict_name, dict_type, status, create_by, create_time, remark",
		"from t_dict_type",
		"<where>",
		"<if test=\"dictName != null and dictName != ''\">",
		"AND dict_name like concat('%', #{dictName}, '%')",
		"</if>",
		"<if test=\"status != null and status != ''\">",
		"AND status = #{status}",
		"</if>",
		"<if test=\"dictType != null and dictType != ''\">",
		"AND dict_type like concat('%', #{dictType}, '%')",
		"</if>",
		"<if test=\"params.beginTime != null and params.beginTime != ''\">",
		"and date_format(create_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')",
		"</if>",
		"<if test=\"params.endTime != null and params.endTime != ''\">",
		"and date_format(create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')",
		"</if>",
		"</where>",
		"</script>"})
	public List<DictType> selectDictTypeList(DictType dictType);

	/**
	 * 根据所有字典类型
	 * 
	 * @return 字典类型集合信息
	 */
	@Select("select dict_id, dict_name, dict_type, status, create_by, create_time, remark from t_dict_type")
	public List<DictType> selectDictTypeAll();

	/**
	 * 根据字典类型ID查询信息
	 * 
	 * @param dictId 字典类型ID
	 * @return 字典类型
	 */
	@Select("select dict_id, dict_name, dict_type, status, create_by, create_time, remark " +
			"from t_dict_type " +
			"where dict_id = #{dictId}")
	public DictType selectDictTypeById(Long dictId);

	/**
	 * 根据字典类型查询信息
	 * 
	 * @param dictType 字典类型
	 * @return 字典类型
	 */
	@Select("select dict_id, dict_name, dict_type, status, create_by, create_time, remark " +
			"from t_dict_type " +
			"where dict_type = #{dictType}")
	public DictType selectDictTypeByType(String dictType);

	/**
	 * 通过字典ID删除字典信息
	 * 
	 * @param dictId 字典ID
	 * @return 结果
	 */
	@Delete("delete from t_dict_type where dict_id = #{dictId}")
	public int deleteDictTypeById(Long dictId);

	/**
	 * 批量删除字典类型
	 * 
	 * @param ids 需要删除的数据
	 * @return 结果
	 */
	@Delete({"<script>",
		"delete from t_dict_type where dict_id in",
		"<foreach collection=\"array\" item=\"dictId\" open=\"(\" separator=\",\" close=\")\">",
		"#{dictId}",
		"</foreach>",
		"</script>"})
	public int deleteDictTypeByIds(Long[] ids);

	/**
	 * 新增字典类型信息
	 * 
	 * @param dictType 字典类型信息
	 * @return 结果
	 */
	@Insert({"<script>",
		"insert into t_dict_type(",
		"<if test=\"dictName != null and dictName != ''\">dict_name,</if>",
		"<if test=\"dictType != null and dictType != ''\">dict_type,</if>",
		"<if test=\"status != null\">status,</if>",
		"<if test=\"remark != null and remark != ''\">remark,</if>",
		"<if test=\"createBy != null and createBy != ''\">create_by,</if>",
		"create_time",
		")values(",
		"<if test=\"dictName != null and dictName != ''\">#{dictName},</if>",
		"<if test=\"dictType != null and dictType != ''\">#{dictType},</if>",
		"<if test=\"status != null\">#{status},</if>",
		"<if test=\"remark != null and remark != ''\">#{remark},</if>",
		"<if test=\"createBy != null and createBy != ''\">#{createBy},</if>",
		"sysdate()",
		")",
		"</script>"})
	public int insertDictType(DictType dictType);

	/**
	 * 修改字典类型信息
	 * 
	 * @param dictType 字典类型信息
	 * @return 结果
	 */
	@Update({"<script>",
		"update t_dict_type",
		"<set>",
		"<if test=\"dictName != null and dictName != ''\">dict_name = #{dictName},</if>",
		"<if test=\"dictType != null and dictType != ''\">dict_type = #{dictType},</if>",
		"<if test=\"status != null\">status = #{status},</if>",
		"<if test=\"remark != null\">remark = #{remark},</if>",
		"<if test=\"updateBy != null and updateBy != ''\">update_by = #{updateBy},</if>",
		"update_time = sysdate()",
		"</set>",
		"where dict_id = #{dictId}",
		"</script>"})
	public int updateDictType(DictType dictType);

	/**
	 * 校验字典类型称是否唯一
	 * 
	 * @param dictType 字典类型
	 * @return 结果
	 */
	@Select("select dict_id, dict_name, dict_type, status, create_by, create_time, remark " +
			"from t_dict_type " +
			"where dict_type = #{dictType} limit 1")
	public DictType checkDictTypeUnique(String dictType);
}
